feat(storage): tenant-scoped trace_id uniqueness (RAN-21)#29
Merged
Conversation
Replace standalone uniqueIndex on Trace.TraceID with composite idx_traces_tenant_trace_id(tenant_id, trace_id) so two tenants can ingest the same trace_id without either dropping into OnConflict.DoNothing. AutoMigrateModels now idempotently discovers and drops any legacy single-column unique index on traces.trace_id (SQLite/Postgres/MySQL/MSSQL) so upgraded databases stop silently blocking cross-tenant reuse. Co-Authored-By: Paperclip <noreply@paperclip.ing>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Replace
Trace.TraceID's standaloneuniqueIndexwith compositeidx_traces_tenant_trace_idon(tenant_id, trace_id)so two tenants can ingest identicaltrace_ids without either silently dropping intoOnConflict.DoNothing.AutoMigrateModelsnow idempotently discovers and drops any pre-existing single-column unique index ontraces.trace_id(SQLite / Postgres / MySQL / MSSQL), so upgraded databases stop silently blocking cross-tenant reuse on first boot post-RAN-21. Discovery is structure-based — the composite index is two columns and is never matched.Files
internal/storage/models.go— compositeuniqueIndex:idx_traces_tenant_trace_iddeclared onTrace.TenantID(priority 1) andTrace.TraceID(priority 2). StandaloneuniqueIndexremoved fromTraceID.internal/storage/factory.go—dropLegacyTraceIDUniqueIndexinvoked afterAutoMigrateinAutoMigrateModels. Failures log but do not abort boot.internal/storage/trace_repo.go— comments tightened onCreateTrace/BatchCreateTraces(per-tenant dedupe semantics) andGetTrace(child Preload now defense-in-depth, not collision protection).internal/storage/migrate_traces.go(new) — per-driver legacy-index discovery; idempotent.internal/storage/trace_tenant_test.go(new) — six acceptance tests, all green on SQLite.Test plan
go vet ./...cleango build ./...cleango test -count=1 ./...— all packages green; 6 new tests cover cross-tenantCreateTrace+BatchCreateTraces, intra-tenant dedupe still works,GetTracechild isolation, legacy-index drop on simulated upgrade, composite index landed on fresh DB.build · vet · testCI check (required) — armed for auto-merge.Paperclip
Refs RAN-21.